package com.yl.module.property.domain;


import java.time.LocalDateTime;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.yl.module.property.domain.dto.JiankePushDataDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.IdType;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 智能资产运行数据表 此表数据来源于建科 实体
 * @author makejava
 * @date 2024-10-23 15:54:16
 */
@Data
@Accessors(chain = true)
@TableName("property_run_data")
@ApiModel(value = "PropertyRunData", description = "智能资产运行数据表 此表数据来源于建科")
public class PropertyRunData extends Model<PropertyRunData> implements Serializable {
	private static final long serialVersionUID = -83401313740621692L;

    @ApiModelProperty(value = "智能资产运行数据表-主键id")
	@TableId(value = "id", type = IdType.AUTO)
    private Integer id;

	@ApiModelProperty(value = "数据类型 0位置 1通信状态（是否离线）2告警状态（是否存在告警）3设备属性参数")
	@TableField("`type`")
    private Integer type;

	@ApiModelProperty(value = "资产唯一id")
	@TableField("`property_unique_code`")
    private String propertyUniqueCode;

	@ApiModelProperty(value = "原样保存建科传过来的json数据")
	@TableField("`json_data`")
    private String jsonData;

	@ApiModelProperty(value = "是否是最新的数据 0否 1是 默认1")
	@TableField("`is_new`")
	private Integer isNew;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField("`create_time`")
    private LocalDateTime createTime;

	@TableField("`delete_flag`")
    private Integer deleteFlag;

	@Getter
	public enum JiankeRequestTypeEnum{

		TYPE_1(1,"通信状态（是否在线）"),
		TYPE_2(2,"告警状态（是否存在告警）"),
		TYPE_3(3,"设备运行读数"),
		TYPE_4(4,"设备操作数据 目前表示了灯开关、窗帘开合的数据");

		private final Integer code;
		private final String name;

		JiankeRequestTypeEnum(
				Integer code,
				String name
		){
			this.code = code;
			this.name = name;
		}
	}

	@Getter
	public enum DeviceDataTypeEnum{

		TYPE_1(1,"灯开关"),
		TYPE_2(2,"窗帘开合");

		private final Integer code;
		private final String name;

		DeviceDataTypeEnum(
				Integer code,
				String name
		){
			this.code = code;
			this.name = name;
		}
	}

	/**
	 * 当type=1
	 * 数据体data 表示是否在线
	 */
	@Data
	public class lineState{
		@ApiModelProperty(value = "是否在线 0否 1是")
		private Integer state;
	}

	/**
	 * 当type=2
	 * 数据体data 表示是否告警
	 */
	@Data
	public class AlarmState{
		@ApiModelProperty(value = "是否告警 0否 1是")
		private Integer state;
	}

	/**
	 * 当type=3
	 * 数据体data 表示设备属性参数
	 */
	@Data
	public static class DeviceAttribute{
		@ApiModelProperty(value = "设备运行读数")
		private List<DeviceReadsItem> deviceReads;
	}

	/**
	 * 当type=4
	 * 数据体data 表示设备操作数据 目前表示了灯开关、窗帘开合的数据
	 */
	@Data
	public static class DeviceOperation{
		@ApiModelProperty(value = "设备操作类型 1灯 2窗帘")
		private Integer deviceDataType;

		@ApiModelProperty(value = "设备操作属性参数")
		private List<DeviceReadsItem> operationData;
	}

	@Data
	public static class DeviceReadsItem{
		@ApiModelProperty(value = "设备属性 字段key")
		private String key;
		@ApiModelProperty(value = "设备属性 字段key名称 例如湿度、温度")
		private String keyName;
		@ApiModelProperty(value = "设备属性 字段key对应的value值 例如湿度就是45 温度就是32°")
		private String value;
	}

	public static void main(String[] args) {
		PropertyRunData.DeviceAttribute device = new PropertyRunData.DeviceAttribute();

		PropertyRunData.DeviceReadsItem item = new PropertyRunData.DeviceReadsItem();
		item.setKey("temperature");
		item.setValue("温度");
		item.setKeyName("32°");

		PropertyRunData.DeviceReadsItem item2 = new PropertyRunData.DeviceReadsItem();
		item2.setKey("humidity");
		item2.setValue("湿度");
		item2.setKeyName("55");

		List<PropertyRunData.DeviceReadsItem> deviceReads = new ArrayList<>();
		deviceReads.add(item);
		deviceReads.add(item2);

		device.setDeviceReads(deviceReads);

		System.out.println(JSONUtil.toJsonStr(device));
	}


}

